from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-23 14:04:08.077025
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 23, Dec, 2021
Time: 14:04:12
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5984
Nobs: 514.000 HQIC: -48.0501
Log likelihood: 5949.68 FPE: 1.01323e-21
AIC: -48.3412 Det(Omega_mle): 8.51908e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356466 0.077856 4.579 0.000
L1.Burgenland 0.099830 0.043618 2.289 0.022
L1.Kärnten -0.115560 0.022511 -5.133 0.000
L1.Niederösterreich 0.178977 0.090581 1.976 0.048
L1.Oberösterreich 0.120995 0.091170 1.327 0.184
L1.Salzburg 0.282446 0.047009 6.008 0.000
L1.Steiermark 0.021893 0.060647 0.361 0.718
L1.Tirol 0.109650 0.048924 2.241 0.025
L1.Vorarlberg -0.081122 0.043204 -1.878 0.060
L1.Wien 0.032376 0.082472 0.393 0.695
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014941 0.171816 0.087 0.931
L1.Burgenland -0.048119 0.096258 -0.500 0.617
L1.Kärnten 0.035356 0.049679 0.712 0.477
L1.Niederösterreich -0.207877 0.199898 -1.040 0.298
L1.Oberösterreich 0.455904 0.201197 2.266 0.023
L1.Salzburg 0.313894 0.103741 3.026 0.002
L1.Steiermark 0.107333 0.133838 0.802 0.423
L1.Tirol 0.316379 0.107968 2.930 0.003
L1.Vorarlberg 0.010975 0.095345 0.115 0.908
L1.Wien 0.011227 0.182004 0.062 0.951
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217299 0.039711 5.472 0.000
L1.Burgenland 0.092455 0.022248 4.156 0.000
L1.Kärnten -0.005274 0.011482 -0.459 0.646
L1.Niederösterreich 0.226214 0.046201 4.896 0.000
L1.Oberösterreich 0.165306 0.046502 3.555 0.000
L1.Salzburg 0.037592 0.023977 1.568 0.117
L1.Steiermark 0.029903 0.030933 0.967 0.334
L1.Tirol 0.078190 0.024954 3.133 0.002
L1.Vorarlberg 0.055678 0.022037 2.527 0.012
L1.Wien 0.103637 0.042066 2.464 0.014
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155228 0.039203 3.960 0.000
L1.Burgenland 0.043188 0.021963 1.966 0.049
L1.Kärnten -0.013140 0.011335 -1.159 0.246
L1.Niederösterreich 0.156325 0.045610 3.427 0.001
L1.Oberösterreich 0.342038 0.045907 7.451 0.000
L1.Salzburg 0.100099 0.023670 4.229 0.000
L1.Steiermark 0.112706 0.030538 3.691 0.000
L1.Tirol 0.089407 0.024635 3.629 0.000
L1.Vorarlberg 0.054518 0.021755 2.506 0.012
L1.Wien -0.041344 0.041528 -0.996 0.319
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149107 0.074266 2.008 0.045
L1.Burgenland -0.034729 0.041606 -0.835 0.404
L1.Kärnten -0.036612 0.021473 -1.705 0.088
L1.Niederösterreich 0.131282 0.086403 1.519 0.129
L1.Oberösterreich 0.178367 0.086965 2.051 0.040
L1.Salzburg 0.256389 0.044841 5.718 0.000
L1.Steiermark 0.080365 0.057850 1.389 0.165
L1.Tirol 0.134333 0.046668 2.878 0.004
L1.Vorarlberg 0.104897 0.041212 2.545 0.011
L1.Wien 0.039197 0.078669 0.498 0.618
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.078372 0.058803 1.333 0.183
L1.Burgenland 0.016319 0.032944 0.495 0.620
L1.Kärnten 0.050801 0.017002 2.988 0.003
L1.Niederösterreich 0.181791 0.068414 2.657 0.008
L1.Oberösterreich 0.331005 0.068859 4.807 0.000
L1.Salzburg 0.050905 0.035505 1.434 0.152
L1.Steiermark -0.004184 0.045805 -0.091 0.927
L1.Tirol 0.127222 0.036951 3.443 0.001
L1.Vorarlberg 0.059521 0.032631 1.824 0.068
L1.Wien 0.109605 0.062290 1.760 0.078
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173656 0.071181 2.440 0.015
L1.Burgenland 0.010404 0.039878 0.261 0.794
L1.Kärnten -0.061003 0.020581 -2.964 0.003
L1.Niederösterreich -0.110610 0.082814 -1.336 0.182
L1.Oberösterreich 0.232170 0.083353 2.785 0.005
L1.Salzburg 0.039652 0.042978 0.923 0.356
L1.Steiermark 0.262417 0.055447 4.733 0.000
L1.Tirol 0.488958 0.044729 10.931 0.000
L1.Vorarlberg 0.070155 0.039500 1.776 0.076
L1.Wien -0.102802 0.075401 -1.363 0.173
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.140520 0.078833 1.782 0.075
L1.Burgenland -0.011070 0.044165 -0.251 0.802
L1.Kärnten 0.062967 0.022794 2.762 0.006
L1.Niederösterreich 0.174342 0.091718 1.901 0.057
L1.Oberösterreich -0.083067 0.092314 -0.900 0.368
L1.Salzburg 0.223919 0.047599 4.704 0.000
L1.Steiermark 0.139238 0.061408 2.267 0.023
L1.Tirol 0.054270 0.049538 1.096 0.273
L1.Vorarlberg 0.140581 0.043747 3.214 0.001
L1.Wien 0.161783 0.083508 1.937 0.053
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.460724 0.043828 10.512 0.000
L1.Burgenland 0.000508 0.024554 0.021 0.983
L1.Kärnten -0.014398 0.012672 -1.136 0.256
L1.Niederösterreich 0.181160 0.050991 3.553 0.000
L1.Oberösterreich 0.254152 0.051322 4.952 0.000
L1.Salzburg 0.019432 0.026463 0.734 0.463
L1.Steiermark -0.008887 0.034140 -0.260 0.795
L1.Tirol 0.074992 0.027541 2.723 0.006
L1.Vorarlberg 0.056801 0.024321 2.335 0.020
L1.Wien -0.022919 0.046426 -0.494 0.622
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.029779 0.092248 0.153701 0.142087 0.069843 0.081105 0.013963 0.208661
Kärnten 0.029779 1.000000 -0.031105 0.134955 0.051670 0.076132 0.454477 -0.078343 0.101557
Niederösterreich 0.092248 -0.031105 1.000000 0.291545 0.105421 0.257373 0.048516 0.148553 0.253870
Oberösterreich 0.153701 0.134955 0.291545 1.000000 0.199817 0.288410 0.153796 0.132719 0.197719
Salzburg 0.142087 0.051670 0.105421 0.199817 1.000000 0.123823 0.058930 0.112127 0.071564
Steiermark 0.069843 0.076132 0.257373 0.288410 0.123823 1.000000 0.131008 0.091268 0.012499
Tirol 0.081105 0.454477 0.048516 0.153796 0.058930 0.131008 1.000000 0.063044 0.125690
Vorarlberg 0.013963 -0.078343 0.148553 0.132719 0.112127 0.091268 0.063044 1.000000 -0.004700
Wien 0.208661 0.101557 0.253870 0.197719 0.071564 0.012499 0.125690 -0.004700 1.000000